using MediatR;
using SumerCoreDevOps.Application.Users.Queries;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Identity;

namespace SumerCoreDevOps.Application.Users.Handlers;

/// <summary>
/// 获取用户（包含角色）查询处理器
/// </summary>
public class GetUserWithRolesQueryHandler : IRequestHandler<GetUserWithRolesQuery, User?>
{
    private readonly UserManager _userManager;

    public GetUserWithRolesQueryHandler(UserManager userManager)
    {
        _userManager = userManager;
    }

    public async Task<User?> Handle(GetUserWithRolesQuery request, CancellationToken cancellationToken)
    {
        return await _userManager.GetUserWithRolesAsync(request.UserId);
    }
}
